home *** CD-ROM | disk | FTP | other *** search
- From: clamage@Eng.Sun.COM (Steve Clamage)
- Message-ID: <4ftia0$c5s@engnews1.Eng.Sun.COM>
- X-Original-Date: 14 Feb 1996 20:56:32 GMT
- Path: in2.uu.net!bounce-back
- Date: 15 Feb 96 00:46:17 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: Initializer w/sizeof() on lhs term, okay o
- Organization: Sun Microsystems Inc.
- References: <4fqq6l$qcr@venus.roc.csci.csc.com>
- Reply-To: clamage@Eng.Sun.COM
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMSKCd+EDnX0m9pzZAQEybwGAk1lAJimToQfDU4RYVm55DPgsGXZYtFxl
- fSppMWu9fcijxNaK6TF9aTtY2hFSDHjl
- =C9v+
-
- In article qcr@venus.roc.csci.csc.com, tottinge@csci.csc.com (Tim
- Ottinger) writes:
-
- >In the following example, the problem is manifest nicely, but the actual
- >code fragment is clearly nonsensical. Forgive this. I didn't want to go
- >chasing down the code again.
-
- >It all comes down to a problem where a sizeof() is used on the rhs of an
- >initialization, and it's operating on the object it's initializing:
- >
- > someType z = fred + sizeof(z);
- > ^ ^^
-
- >Of course, I've changed the inherited code to read:
- >
- > someType z = fred + sizeof(someType);
- > ^ ^^^^^^^^
-
- The original code is valid as shown. The point of declaration of a name is
- immediately after its complete declarator and before its initializer (if any),
- with a few exceptions that don't apply to this particular example.
-
- Thus, 'z' has been declared by the time you get to the '=', so you can
- use 'sizeof(z)' in its initializer. There is no ambiguity, since the size
- of z is the size of 'someType', no matter what the value of the initializer.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. Moderation policy:
- http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
-